RoleManager = {}
local this = RoleManager

function RoleManager.init()
	this.team = {}
	this.deadTeam = {}

	this.enemy = {}
	this.deadEnemy = {}
end

function RoleManager.addFriend(x)
	table.insert(this.team, x)
end

function RoleManager.removeDeadRole(x)
	if(x.isFriend) then
		local deadIndex = -1
		for i,v in ipairs(this.team) do
			if(v == x) then
				deadIndex = i
				break
			end
		end
		if(deadIndex >= 0) then
			table.remove(this.team, deadIndex)
		end
		table.insert(this.deadTeam, x)
	else
		local deadIndex = -1
		for i,v in ipairs(this.enemy) do
			if(v == x) then
				deadIndex = i
				break
			end
		end
		if(deadIndex >= 0) then
			table.remove(this.enemy, deadIndex)
		end
		table.insert(this.deadEnemy, x)
	end
end

function RoleManager.addEnemy(x)
	table.insert(this.enemy, x)
end

function RoleManager.clear()
	this.team = nil
	this.deadTeam = nil

	this.enemy = nil
	this.deadEnemy = nil
end

function RoleManager.isAllDead(isFriendGroup)
	local targetGroup = nil
	if(isFriendGroup) then
		targetGroup = this.team
	else
		targetGroup = this.enemy
	end

	local isAllDead = true
	for i,v in ipairs(targetGroup) do
		if( not v:isDead()) then
			isAllDead = false
			break
		end
	end

	return isAllDead
end